
var _height=wrapHeight-46;// 46地面高度
var gh=60;//管子接口高度
var gwidth=42;//管子宽度
function Block(up,rema){
	this.up=up;//up:上面柱子的高度
	this.rema=rema;//rema：中间空隙的高度
	this.down=_height-up-rema; //下面柱子高度
	this.mid=null;//移动计时器
	this.div=null;//柱子div
	this.speed=1;//柱子移动速度

}
Block.prototype={
	create:function(){
		//创建外层
		var bwrap=document.createElement('div');
		bwrap.className='blockwrap';
		bwrap.style.height=_height;
		wrap.appendChild(bwrap);
		this.div=bwrap;
		//创建柱子
		var upblo=document.createElement('div');
		upblo.className='upblo';
		upblo.style.height=this.up+'px';
		
		var downblo=document.createElement('div');
		downblo.className='downblo';
		downblo.style.height=this.down-60-60+'px';
		bwrap.appendChild(upblo);
		bwrap.appendChild(downblo);
	},
	move:function(){
		var that=this;
		this.mid=setInterval(function(){
			var curleft=window.getComputedStyle(that.div).left;
			curleft=curleft.substring(0,curleft.length-2);
			if(curleft<-gwidth){
				//超出边界移除
				that.mid&&clearInterval(that.mid);
				wrap.removeChild(that.div);
			}
			that.div.style.left=curleft-that.speed+'px';
			that.checkhit();
//			console.log(curleft);
		},40)
	},
	checkhit:function(){
		//检测碰撞
		var bloleft=this.div.style.left;
		var hit=false;
		bloleft=bloleft.substring(0,bloleft.length-2);//柱子当前距左边距离
		if(bloleft<=bird.left+40 && bloleft>=bird.left-42){
			//当柱子移动到鸟的位置后，开始检测碰撞
			var birdtop=bird&&bird.div.style.top;
		    birdtop=birdtop.substring(0,birdtop.length-2);//鸟当前高度
			if(birdtop<(this.up+60) || birdtop>(this.up+60+this.rema)){
				//撞上了
				end();
			}else{
				//没有撞上
				if(bloleft==bird.left-42){
					curscore+=1;
					if(curscore/10>0 && curscore%10==0){
						//调整难度
						lev=curscore/10;
						this.speed+=lev/10;
						level.innerText=lev;
					}
					scodiv.innerText=curscore;
					var that=this;
					setTimeout(function(){
						that.remove();
						that.create();
						that.move();
					},2000);
					
				}
			}
		}
	},
	remove:function(){
		wrap.removeChild(this.div);
		clearInterval(this.mid);
	}
}
